package fu.capstone.hanoicityguide.common.utility;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;

import com.facebook.UiLifecycleHelper;
import com.facebook.widget.FacebookDialog;

public class SharingFacebook {
	

	public SharingFacebook() {

	}

	public static void shareFacebook(UiLifecycleHelper uiHelper, final Context context) {
//		uiHelper = new UiLifecycleHelper((Activity) context, null);

		if (FacebookDialog.canPresentShareDialog(
				context.getApplicationContext(),
				FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
			// Publish the post using the Share Dialog
			FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(
					(Activity) context)
					.setLink("https://play.google.com/store/apps/details?id=fu.capstone.hanoicityguide")
//					.setPicture(picture)
					.setCaption("Let HANOI talk to you!")
					.setDescription("HCG is awesome! Try it now!")
					.build();
			uiHelper.trackPendingDialogCall(shareDialog.present());

		} else {
			new AlertDialog.Builder(context)
					.setTitle("Request installation!")
					.setMessage(
							"You need to install Facebook application to use this feature!")
					.setPositiveButton("Install",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {
									// go to google play
									Intent intent;
									intent = new Intent(Intent.ACTION_VIEW);
									intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
									intent.setData(Uri
											.parse("market://details?id="
													+ "com.facebook.katana"));
									context.startActivity(intent);
								}
							})
					.setNegativeButton("Cancel",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {
									// do nothing, dismiss the dialog
									dialog.cancel();
								}
							}).setIcon(android.R.drawable.ic_dialog_alert)
					.show();
		}

	}
}
